package com.dhecp.project.statistics.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.dhecp.core.constant.DataFiltering;
import com.dhecp.core.utils.PageUtils;
import com.dhecp.project.statistics.domain.CommonStatistics;
import com.dhecp.project.statistics.mapper.CommonStatisticsMapper;
import com.dhecp.project.statistics.service.CommonStatisticsService;
import com.dhecp.project.system.service.SysDictionaryForFieldService;

/**
 * 通用统计分析  业务实现层
 * @author DH-Xxj
 * @version 2021年2月4日
 */
@Service
public class CommonStatisticsServiceImpl implements CommonStatisticsService {

	@Autowired
	private CommonStatisticsMapper commonStatisticsMapper;

	@Autowired
	private SysDictionaryForFieldService dictionaryForFieldService;

	/**
	 * 通用存储过程查询统计
	 * @param params
	 * @return List - CommonStatistics
	 * @throws Exception
	 * @author DH-Xxj
	 */
	@Override
	public List<CommonStatistics> queryStatisticsList(Map<String, Object> params) throws Exception {
        params.put(DataFiltering.TABLE_ALIAS, "t1");	//查询表别名
        params.put(DataFiltering.WHERE_SCODE, dictionaryForFieldService.getWhereStr(params));	//查询条件字SQL语句，一般在存储过程中使用
        params.put(DataFiltering.DATA_SCODE, dictionaryForFieldService.getDataScode(params));	//数据权限查询条件SQL语句
        
		return commonStatisticsMapper.findStatisticsList(params);
	}
	
	/**
	 * 通用视图查询统计
	 * @param parems
	 * @return List - CommonStatistics
	 * @throws Exception
	 * @author DH-Xxj
	 */
	@Override
	public List<CommonStatistics> queryViewStatisticsList(Map<String, Object> params) throws Exception {
        params.put(DataFiltering.TABLE_ALIAS, "t1");	//查询表别名
		params.put(DataFiltering.DATA_WHERE, dictionaryForFieldService.getWhereStr(params));	//常规查询条件SQL语句
        params.put(DataFiltering.DATA_SCODE, dictionaryForFieldService.getDataScode(params));	//数据权限查询条件SQL语句

		if (params.get("field") == null || params.get("field") == ""){
			String orderBy = "v10 desc";
			PageUtils.startPageOrder(orderBy);
		}else{
			PageUtils.startPage();	
		}	
		return commonStatisticsMapper.findViewStatisticsList(params);
	}
	
	/**
	 * 查询销售合同收款情况分析（出库单弹窗分析）
	 * @param parems
	 * @return List - CommonStatistics
	 * @throws Exception 
	 * @author DH-Xxj
	 */
	@Override
	public List<CommonStatistics> queryStockBargainInSkQkFx(Map<String, Object> params) throws Exception {
        params.put(DataFiltering.TABLE_ALIAS, "t1");	//查询表别名
		params.put(DataFiltering.DATA_WHERE, dictionaryForFieldService.getWhereStr(params));	//常规查询条件SQL语句
        params.put(DataFiltering.DATA_SCODE, dictionaryForFieldService.getDataScode(params));	//数据权限查询条件SQL语句

		PageUtils.startPage();	
		return commonStatisticsMapper.findStockBargainInSkQkFx(params);
	}

}
